package com.zdp.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author sesshomaru
 * @date 2021/7/4 23:07
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    // 配置webjars共模板页使用
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("/webjars/")
                .resourceChain(false);
        registry.setOrder(1);
    }

    // 因为登录页被自定义到/login路径，这里需要将/login和视图login.html进行映射
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // setViewName("login") 不需要带.html
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/").setViewName("index");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}
